<?php

namespace catchAdmin\model;

use catcher\exceptions\AlertErrorException;

class ZhaoPinBao extends ModelApp
{


    ############################ 关系 start ###############################

    public function userExt()
    {
        return $this
            ->hasOne(UserExt::class, 'wechat_user_id', 'wechat_user_id');
    }


    public function zhaoPin()
    {
        return $this
            ->hasOne(ZhaoPin::class, 'id', 'zhao_pin_id');
    }


    ############################ 关系 end ###############################

    public function saveDataApp($param)
    {
        $msg_arr = [
            'zhao_pin_id'    => $param['zhao_pin_id'],
            'wechat_user_id' => $this->getLoginId(),
        ];

        if ($this->getLoginUser()['company_type'] == 1 && $this->getLoginUser()['company_status'] == 3) {
        } else {
            throw new AlertErrorException('只有个人认证才能报名');
        }

        if ($this
                ->where($msg_arr)
                ->count() > 0) {
            throw new AlertErrorException('不能重复报名');
        }

        return parent::saveDataCC($msg_arr);
    }

}
